<?php
namespace Common\Behavior;
use Common\Library\Exception\BadRequest;
/**
 * 接口token校验
 *
 * @property   $name Description
 * 
 * @author wangzhenxian
 * @package application.components 
 */
class ApiTokenBehavior extends \Think\Behavior{
    
    public function run(&$params) {
        
//       if(MODULE_NAME=='Collect'){
//           return true;
//       }
       $api_token = I('api_token');
       $app_key =  I('app_key');
      
       if(empty($app_key)||empty($api_token)){
           throw new BadRequest("参数异常", 1);
       }
       //echo strtolower(MODULE_NAME.CONTROLLER_NAME.ACTION_NAME).date('Y-m-d',time()).C('app_secrets')[$app_key];
       $server_api_token = md5(strtolower(MODULE_NAME.CONTROLLER_NAME.ACTION_NAME).date('Y-m-d',time()).C('app_secrets')[$app_key]);
       //echo $server_api_token;
       if($server_api_token!=$api_token) {
           throw new BadRequest("api_token校验异常，服务端拒绝提供服务", 0);
       }
    }
}
